1941B - Rudolf and 121 - CodeForces Solution


greedy math

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n=int(input())
    l1=list(map(int, input().split()))

    for i in range(1, n-1):
        l1[i+1]-=l1[i-1]
        l1[i]-=2*l1[i-1]
        l1[i-1]=0
        if l1[i]<0 or l1[i+1]<0:
            print('NO')
            break
    else:
        if l1[-1]==0 and l1[-2]==0:
            print('YES')
        else:
            print('NO')
                    


Comments

Submit
0 Comments
More Questions

1283B - Candies Division
1451B - Non-Substring Subsequence
1408B - Arrays Sum
1430A - Number of Apartments
1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language
600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down